package cn.mldn.myclass.scanner;


import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class ScannerTest2 {
    private static void readfile(String filename) {
        try {
            Scanner scanner = new Scanner(new File(filename));
            //相对目录  最外层的工程目录

            String property = System.getProperty("line.separator"); //    \r\n
            String property1 = System.getProperty("user.dir"); //    \r\n
            scanner.useDelimiter(System.getProperty("line.separator"));

            while (scanner.hasNext()) {//是否还有下一个标记
                parseline(scanner.next());//下一个袁术
            }
            scanner.close();
        } catch (FileNotFoundException e) {
            System.out.println(e);
        }
    }

    private static void parseline(String line) {
        Scanner linescanner = new Scanner(line);
        linescanner.useDelimiter(",");
        //可以修改usedelimiter参数以读取不同分隔符分隔的内容
        String name = linescanner.next();
        int age = linescanner.nextInt();
        String idate = linescanner.next();
        boolean iscertified = linescanner.nextBoolean();
        System.out.println("姓名：" + name + " ，年龄：" + age + " ，入司时间：" + idate + " ，验证标记：" + iscertified);
    }

    private static void useDelimiter1()
    {


       /* Scanner默认使用空格作为分割符来分隔文本，但允许你指定新的分隔符
        --将注释行去掉，使用空格或逗号或点号作为分隔符，输出结果如下：*/


        Scanner s = new Scanner("123 asdf sd 45 789 sdf asdfl,sdf.sdfl,asdf    ......asdfkl    las");
//                s.useDelimiter(" |,|\\.");
        while (s.hasNext()) {
            System.out.println(s.next());
        }

    }

    public static void main(String[] args) {

          readfile("scanner.txt");
        System.out.println("===================================");
        useDelimiter1();
    }

}